import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/4 15:08
 * @description 简单前缀和 , 注意用long保存数据，防止溢出
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int minimumAverageDifference(int[] nums) {
        int n = nums.length;
        if (n == 0) {
            return 0;
        }
        long[] preSum = new long[n + 1];
        for (int i = 0; i < n; i++) {
            preSum[i + 1] = preSum[i] + nums[i];
        }
        int minIndex = 0, min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int na = i + 1, nb = n - i - 1;
            int a = (int) (preSum[i + 1] / na);
            int b = nb == 0 ? 0 : (int) ((preSum[n] - preSum[i + 1]) / nb);
            if (Math.abs(a - b) < min) {
                min = Math.abs(a - b);
                minIndex = i;
            }
        }
        return minIndex;
    }
}
